<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
/*
	签到记录
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';

$tabs=array(
	 
	array('op'=>'fx','title'=>'分校管理'),
	array('op'=>'pk','title'=>'排课管理'),
	array('op'=>'xs','title'=>'学生管理'),
	array('op'=>'qd','title'=>'签到管理'),
	array('op'=>'pj','title'=>'评价管理'),	
);


if($_RQ['op']=='fx'){

 
	exi('','','jy_kexie/store.index/','');

}
if($_RQ['op']=='pk'){

	 
	exi('','','jy_kexie/store.lesson_pai/','');

	
}
if($_RQ['op']=='xs'){

	
	exi('','','jy_kexie/store.user/','');


}
if($_RQ['op']=='qd'){

	
	exi('','','jy_kexie/store.sign//type=0','');


}
if($_RQ['op']=='pj'){

	exi('','','jy_kexie/store.comment//type=0','');

}

if($_RQ['op']=='list'){
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$params=array('uniacid'=>$_SESSION['uniacid'],'storeid'=>$this->store_id);
	$return['params']=array();	
	//会员ID
	if(!empty($_RQ['mid'])){
		$params['mid']=intval($_RQ['mid']);
		$return['params']['mid']=$_RQ['mid'];
	}
	//type
	$params['type']=intval($_RQ['type']);
	$return['params']['type']=$_RQ['type'];
	if(!empty($_RQ['name'])){
		$nameparams=array('uniacid'=>$_SESSION['uniacid']);
		$nameparams['name like']='%'.trim($_RQ['name']).'%';
		$return['params']['name']=$_RQ['name'];
		if($params['type']==0){
			$mids=pdo_getall('jy_kexie_user',$nameparams,'mid','mid');
		}else{
			$mids=pdo_getall('jy_kexie_worker',$nameparams,'mid','mid');
		}
		if($mids){
			$mids=array_keys($mids);
		}else{
			$mids=-1;
		}
		$params['mid']=$mids;
	}
	//时间范围
	if(!empty($_RQ['tstart']) && $_RQ['tstart'] !='1970-01-01 08:00'){
		$tstart=strtotime($_RQ['tstart']);
		$return['params']['tstart']=trim($_RQ['tstart']);
	}
	if(!empty($_RQ['tend']) && $_RQ['tend'] !='1970-01-01 08:00'){
		$tend=strtotime($_RQ['tend']);
		$return['params']['tend']=trim($_RQ['tend']);
	}
	if($tstart && $tend){
		$params['createtime between']=array($tstart,$tend);
	}elseif($tstart){
		$params['createtime >']=$tstart;
	}elseif($tend){
		$params['createtime <']=$tend;
	}
	$parameter=array('params'=>$params,'limit'=>array($pindex,$psize));
	$orderby='id desc';
	$list=pdo_getslice('jy_kexie_sign',$params,array($pindex,$psize),$total,'','',$orderby);
	if($list){
		foreach($list as &$log){
			$log['date']=date('Y-m-d',$log['createtime']);
			$member=model('core/member')->detail($item['mid'],array('credit1','credit2','mobile','groupid','avatar','nickname'));
			$item['member']=$member;
			if($item['type']==0){
				$item['username']=pdo_getcolumn('jy_kexie_user',array('id'=>$item['user_id'],'uniacid'=>$_SESSION['uniacid']),'name');
			}else{
				$item['username']=pdo_getcolumn('jy_kexie_worker',array('id'=>$item['user_id'],'uniacid'=>$_SESSION['uniacid']),'name');
			}
			$log['pai']=pdo_get('jy_kexie_lesson_pai',array('id'=>$log['lesson_paiid']));
			$log['pai']['images']=json_decode($log['pai']['images'],true);
			$log['pai']['image']=$log['pai']['images'][0];
			$log['lessontitle']=pdo_getcolumn('jy_kexie_lesson',array('id'=>$log['pai']['lessonid']),'title');
		}
	}
	$return['list']=$list?$list:array();
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'export'=>'export',
		'tabs'=>array(
			array('op'=>'list','title'=>'签到记录'),
		),
		'list'=>array('data'=>'list','edit'=>false,'del_one'=>false,'delall'=>false,'list'=>array(
			array('name'=>'mid','title'=>'会员ID','type'=>'string'),
			array('name'=>'username','title'=>'姓名','type'=>'string'),
			array('name'=>'lessontitle','title'=>'课程','type'=>'string'),
			array('name'=>'storeid','title'=>'所属学校','type'=>'select','options'=>'stores'),
			array('name'=>'date','title'=>'签到日期','type'=>'string'),
			array('name'=>'pai.tingnum','title'=>'签到人数','type'=>'string'),
			array('name'=>'pai.image','title'=>'签到照片','type'=>'image'),
			array('name'=>'createtime','title'=>'签到时间','type'=>'time'),
			array('name'=>'storetime','title'=>'分校签到','type'=>'time'),
		),'action'=>array(
			array('type'=>'href','op'=>'sign','title'=>'分校签到 ','show'=>array('type'=>1,'storetime'=>0)),
		)),
		'search_one'=>array('name'=>'name','add'=>false),
	);
	$return['stores']=pdo_getall('jy_kexie_store',array('uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='sign'){
	if($_RQ['postdata']){
		$post=get_postdata();
		$id=intval($post['id']);
		if(!$post['storetime']){
			exi('请选择签到时间！','erro');
		}
		$update=array('storetime'=>strtotime($post['storetime']));
		pdo_update('jy_kexie_sign',$update,array('id'=>$id));
		exi('分校签到成功！','','goback');
	}
	$id=intval($_RQ['id']);
	$item=array('id'=>$id);	
	$htmls=array(
		'type'=>'edit',
		'desc'=>'分校签到',
	);
	$htmls['edit']=array(
		array('type'=>'time','title'=>'签到时间','name'=>'storetime'),
	);
	$return['htmls']=$htmls;
	$return['item']=$item;
	exi($return);
}
if($_RQ['op']=='export'){
	$params=array('uniacid'=>$_SESSION['uniacid'],'storeid'=>$this->store_id);
	//type
	$params['type']=intval($_RQ['type']);
	$return['params']['type']=$_RQ['type'];
	if(!empty($_RQ['name'])){
		$nameparams=array('uniacid'=>$_SESSION['uniacid']);
		$nameparams['name like']='%'.trim($_RQ['name']).'%';
		$return['params']['name']=$_RQ['name'];
		if($params['type']==0){
			$mids=pdo_getall('jy_kexie_user',$nameparams,'mid','mid');
		}else{
			$mids=pdo_getall('jy_kexie_worker',$nameparams,'mid','mid');
		}
		if($mids){
			$mids=array_keys($mids);
		}else{
			$mids=-1;
		}
		$params['mid']=$mids;
	}
	$sign=pdo_getall('jy_kexie_sign',$params);
	foreach($sign as &$log){
			$log['createtime']=date('Y-m-d',$log['createtime']);
			$member=model('core/member')->detail($log['mid'],array('credit1','credit2','mobile','groupid','avatar','nickname'));
			$log['member']=$member;
			if($log['type']==0){
				$log['username']=pdo_getcolumn('jy_kexie_user',array('mid'=>$log['mid'],'uniacid'=>$_SESSION['uniacid']),'name');
			}else{
				$log['username']=pdo_getcolumn('jy_kexie_worker',array('mid'=>$log['mid'],'uniacid'=>$_SESSION['uniacid']),'name');
			}
			$log['pai']=pdo_get('jy_kexie_lesson_pai',array('id'=>$log['lesson_paiid']));
			$log['storeid']=$log['pai']['storeid'];
			$log['pai']['images']=json_decode($log['pai']['images'],true);
			$log['pai']['image']=$log['pai']['images'][0];
			$log['tingnum']=$log['pai']['tingnum'];
			$log['lessontitle']=pdo_getcolumn('jy_kexie_lesson',array('id'=>$log['pai']['lessonid']),'title');
			$log['storetitle']=pdo_getcolumn('jy_kexie_store',array('id'=>$log['storeid']),'title');
	}
	$header=array(
		'username'=>'姓名',
		'lessontitle'=>'课程',
		'storetitle'=>'所属学校',
		'tingnum'=>'签到人数',
		'createtime'=>'签到时间',
	);
	cfc('tools')->export2excel($header,$sign,'签到表');
}